import el from 'element-ui/src/locale/lang/el'
import fa from 'element-ui/src/locale/lang/fa'

export default {
  state: {
    userId: 0,   //保存用户的编号
    username: '',  //保存用户的名字
    avatarUrl: '',   //用户的头像
    followeds: 0,//动态
    follows: '0',//关注
    gender: '0',//粉丝
    token: '',
    show: false
  },
  mutations: {
    setUser(state, data) {
      state.userId = data.profile.userId
      state.username = data.profile.nickname
      state.avatarUrl = data.profile.avatarUrl
      state.followeds = data.profile.followeds
      state.follows = data.profile.follows
      state.gender = data.profile.gender
      window.localStorage.setItem('userId', data.profile.userId)
      window.localStorage.setItem('username', data.profile.nickname)
      window.localStorage.setItem('avatarUrl', data.profile.avatarUrl)


      if(data.profile.followeds === undefined){
        window.localStorage.setItem('followeds', '1')
      }else{
        window.localStorage.setItem('followeds', data.profile.followeds)
      }


      if(data.profile.follows === undefined){
        window.localStorage.setItem('follows', '1')
      }else{
        window.localStorage.setItem('follows', data.profile.follows)
      }


      if(data.profile.gender === undefined){
        window.localStorage.setItem('gender', '1')
      }else{
        window.localStorage.setItem('gender', data.profile.gender)
      }


    },
    login(state) {
      if(window.localStorage !== null){
        state.show = !state.show
      }
    },//登录成功
    settoken(state, token) {
      state.token = token
      window.localStorage.setItem('token', token)
    }
  },
  getters: {
    getdata(state) {
      if (state.userId === 0 && window.localStorage.getItem('userId') !== null) {
        state.userId = window.localStorage.getItem('userId')
        state.username = window.localStorage.getItem('username')
        state.avatarUrl = window.localStorage.getItem('avatarUrl')
        state.followeds = window.localStorage.getItem('followeds')
        state.follows = window.localStorage.getItem('follows')
        state.gender = window.localStorage.getItem('gender')
        state.show = true
      }
    }
  },
  namespaced: true  //保证多个模块间的数据不冲突
}